package com.furnitur.modules.portal.controller;

import com.furnitur.common.api.Result;
import com.furnitur.modules.portal.service.PortalUserService;
import com.furnitur.modules.portal.vo.user.PortalUserInfoVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/api/portal/user")
public class PortalUserController {

    @Autowired
    private PortalUserService userService;

    @GetMapping("/info")
    public Result<PortalUserInfoVO> getUserInfo() {
        return Result.success(userService.getCurrentUserInfo());
    }

    @PutMapping("/update")
    public Result<PortalUserInfoVO> updateUserInfo(@RequestBody PortalUserInfoVO userInfo) {
        return Result.success(userService.updateUserInfo(userInfo));
    }

    @PostMapping("/avatar")
    public Result<String> uploadUserProfileImage(@RequestParam("file") MultipartFile file) {
        try {
            String imageUrl = userService.uploadUserProfileImage(file);
            return Result.success(imageUrl);
        } catch (Exception e) {
            return Result.failed(e.getMessage());
        }
    }
} 